package com.cjm.one.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.annotation.IgnoreTenantForAdmin;
import com.cjm.one.common.result.Result;
import com.cjm.one.common.utils.AuthSysUserContextHolder;
import com.cjm.one.model.system.dto.DeptDto;
import com.cjm.one.model.system.entity.SysDept;
import com.cjm.one.model.system.vo.SysDeptAllVo;
import com.cjm.one.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "部门管理",description = "部门管理接口")
@RequestMapping("/admin/system/dept")

public class SysDeptController {
    @Resource
    private SysDeptService sysDeptService;
    /**
     * @description: 获取全部的部门列表信息，并组装成树状结果
     * @author: cjm
     * @date: 2024/9/29 20:59
     * @param: []
     * @return: com.cjm.one.common.result.Result<java.lang.String>
     **/
    @IgnoreTenantForAdmin
    @GetMapping("/all")
    @Operation(summary = "获取全部的部门列表信息，并组装成树状结果")
    public Result<List<SysDeptAllVo>> getAllList(@RequestParam(name = "deptName",required = false) String deptName, @RequestParam(name = "keyWord",required = false) String keyWord){

        return Result.ok(sysDeptService.getAllList(deptName,keyWord));
    }
    @PostMapping("/list")
    @IgnoreTenantForAdmin
    @Operation(summary = "获取当前登录用户下的部门列表信息")
    public Result<Page<SysDept>> getUserDeptList(@RequestBody DeptDto deptDto){
        Page<SysDept> page = new Page(deptDto.getCurrent(), deptDto.getSize());
        return Result.ok(sysDeptService.getUserDeptList(page,deptDto));
    }
    @PostMapping
    @Operation(summary = "新增部门信息")
    public Result<Boolean> save(@RequestBody SysDept sysDept){
        return Result.ok(sysDeptService.save(sysDept));
    }
    @PutMapping
    @Operation(summary = "更新部门信息")
    public Result<Boolean> update(@RequestBody SysDept sysDept){
        return Result.ok(sysDeptService.updateById(sysDept));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取部门详情")
    public Result<SysDept> getById(@PathVariable Long id){
        return Result.ok(sysDeptService.getById(id));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除部门")
    public Result<Boolean> removeById(@PathVariable Long id){
        return Result.ok(sysDeptService.removeDeptById(id));
    }


}
